from PySide6 import QtWidgets,QtCore,QtMultimedia
import system

class W1(QtWidgets.QWidget):
    def __init__(self,parent=None):
        super().__init__(parent)
        self.m_pSoundEffect =QtMultimedia.QSoundEffect()
        self.m_pSoundEffect.playingChanged.connect(self.OnPlayingChanged())
        dirpath = system.get_dirpath()
        AUDIO_MOVE = str(dirpath / 'audios/capture.wav')
        self.OnPlayVoice(AUDIO_MOVE);
    def OnPlayVoice(self, fileName):#播放wav文件
        self.m_pSoundEffect.setSource(QtCore.QUrl.fromLocalFile(fileName));
        # m_pSoundEffect->setLoopCount(QSoundEffect.Infinite);注释掉只播放一次，打开循环播放
        self.m_pSoundEffect.setVolume(1.0);
        self.m_pSoundEffect.play();

    def OnPlayingChanged(self):#播放状态改变槽函数
        isPlaying = self.m_pSoundEffect.isPlaying();
        if (not isPlaying):
            print("not playing")
        else:
            print("playing")

    def GetPlayState(self):#获取播放状态
        return self.m_pSoundEffect.isPlaying();
a=QtWidgets.QApplication()
w=W1()
w.show()
a.exec()
